var Element = require('./Element');
var Component = require('./Component');
var VirtualNode = require('./VirtualNode');
var NativeNode = require('./NativeNode');
var TextNode = require('./TextNode');
var hasOwnProperty = Object.prototype.hasOwnProperty;
var ShadowRoot = function (e) {
    VirtualNode.initialize(this, 'shadow', this);
    this.__hostAssociated = false;
    this.__wxHost = e;
    this.__childrenPropsFilter = null;
    this.__slotCacheDirty = false;
};
ShadowRoot.prototype = Object.create(VirtualNode.prototype);
ShadowRoot.create = function (e) {
    var t = new ShadowRoot(e);
    if (e.ownerShadowRoot && e.ownerShadowRoot.__childrenPropsFilter)
        if (t.__childrenPropsFilter)
            for (var i in e.ownerShadowRoot.__childrenPropsFilter)
                t.__childrenPropsFilter[i] || (t.__childrenPropsFilter[i] = e.ownerShadowRoot.__childrenPropsFilter[i]);
        else
            t.__childrenPropsFilter = e.ownerShadowRoot.__childrenPropsFilter;
    return t;
};
ShadowRoot.prototype.createTextNode = function (e) {
    return TextNode._advancedCreate(e, this);
};
ShadowRoot.prototype.createNativeNode = function (e) {
    return NativeNode._advancedCreate(e, this);
};
ShadowRoot.prototype.cloneNativeNode = function (e) {
    return NativeNode._advancedClone(e, this);
};
ShadowRoot.prototype.createVirtualNode = function (e) {
    return VirtualNode._advancedCreate(e, this);
};
ShadowRoot.prototype.getCompDefByTagName = function (e) {
    var t = this.__wxHost;
    return hasOwnProperty.call(t.__using, e) ? t.__using[e] : hasOwnProperty.call(t.__generics, e) ? t.__generics[e] : e;
};
ShadowRoot.prototype.createComponent = function (e, t, i, n) {
    var r = null;
    r = undefined === t ? e : t;
    var o = this.__wxHost;
    'object' != typeof r && 'object' != typeof (r = this.getCompDefByTagName(r)) && (r = Component._list[r] || Component._list['']);
    var s = function (e, t) {
        var i = {};
        for (var n in e) {
            var r = e[n];
            if ('object' != typeof r && hasOwnProperty.call(t.__placeholder, r)) {
                r = t.__placeholder[r];
                if (hasOwnProperty.call(t.__using, r)) {
                    r = t.__using[r];
                } else {
                    hasOwnProperty.call(t.__generics, r) && (r = t.__generics[r] || Component._list['']);
                }
                i[n] = r;
            };
        }
        return i;
    }(i, o);
    i && (i = function (e, t) {
        var i = {};
        for (var n in e) {
            var r = e[n];
            if ('object' != typeof r) {
                if (hasOwnProperty.call(t.__using, r)) {
                    r = t.__using[r];
                } else {
                    hasOwnProperty.call(t.__generics, r) && (r = t.__generics[r] || Component._list['']);
                }
                i[n] = r;
            };
        }
        return i;
    }(i, o));
    'object' == typeof e && (e = r.is);
    o.__componentOptions.randomizeTagName && (e = function () {
        var e = Date.now();
        var t = 'exparser-';
        for (var i = 0; i < 8; i++) {
            var n = (e + Math.floor(26 * Math.random())) % 26;
            e = Math.floor(e / 26);
            t += 'abcdefghijklmnopqrstuvwxyz'[n];
        }
        return t;
    }());
    o.__componentOptions.writeOnly && !r.options.allowInWriteOnly && (r = Component._list['']);
    return Component._advancedCreate(e, r, this, i, s, n);
};
ShadowRoot.prototype.tagNameUsed = function (e) {
    var t = this.__wxHost;
    return !!hasOwnProperty.call(t.__using, e) || (!!hasOwnProperty.call(t.__placeholder, e) || (!!hasOwnProperty.call(t.__generics, e) || !!hasOwnProperty.call(t.__placeholder, e)));
};
ShadowRoot.prototype.getHostNode = function () {
    return this.__wxHost;
};
ShadowRoot.prototype.getElementById = function (e) {
    Element._updateIdMap(this.__wxHost);
    return this.__wxHost.__idCache[e];
};
module.exports = ShadowRoot;
